
	<SCRIPT type="text/javascript" src="js/jquery.validate.js"></SCRIPT>   
    <SCRIPT type="text/javascript" src="js/jquery.kent.js"></SCRIPT>


<?php
if(isset($_POST['btnSignUp']))
{
	$MaKH = $_POST['txtMaKH'];
	$MatKhau = $_POST['txtMatKhau'];
	$HoTen = $_POST['txtHoTen'];
	$GioiTinh = $_POST['rdoGioiTinh'];
	$Email = $_POST['txtEmail'];
	$DienThoai = $_POST['txtDienThoai'];
	$NgaySinh = $_POST['txtNgaySinh'];
	$DiaChi = $_POST['txtDiaChi'];
	$Hinh = $_FILES['fupHinh']['name'];
	
	$sql = "INSERT INTO KhachHang(MaKH, MatKhau, HoTen, GioiTinh, Email, 
				DienThoai, NgaySinh, DiaChi, Hinh, HieuLuc) 
			VALUES('$MaKH', '$MatKhau', '$HoTen', '$GioiTinh', '$Email', 
				'$DienThoai', '$NgaySinh', '$DiaChi', '$Hinh', 0)";
	if(!mysql_query($sql))
	{
		$ThongBaoLoi = mysql_error();
	}
	else
	{
		move_uploaded_file($_FILES['fupHinh']['tmp_name'], "Hinh/KhachHang/".$_FILES['fupHinh']['name']);
		
		include("gmail/mailer.php");
		
		$mail->From = "pnjdang@gmail.com";
		$mail->FromName = "Administrator";
		$mail->AddAddress($Email, $HoTen);
		$mail->Subject = "Welcome mail !";
		$ActivateUrl = "http://$_SERVER[HTTP_HOST]/Webfood/index.php?p=Activate&MaKH=$MaKH";
		$mail->Body = "Click to <a href='$ActivateUrl'>activate</a> your account !";
		
		if(!$mail->Send())
		{
			$ThongBaoLoi = "Unenabled to send mail !";
		}
	}
}
?>
<SCRIPT type="text/javascript">
		
		$(document).ready(function()
		{
			$("#frmSignUp").validate(
			{
				rules: 
				{
					txtMaKH: {required:true}, 
					txtMatKhau: {required:true, minlength:6, matkhau: true},
					txtEmail: {email:true},
				}
			});
		});
	</SCRIPT>  
<script>
$(document).ready(function()
{
	$("#frmSignUp").validate(
	{
		rules:
		{
			txtMaKH: {required: true}
		},
		errorElement: "li"
	});
});	
</script>
<form name="frmSignUp" id="frmSignUp" method="post" enctype="multipart/form-data">
<table cellpadding="5" cellspacing="0" align="left" style="text-align:left">
<tr>
    <td>User Name</td>
    <td>:</td>
    <td>
        <input name="txtMaKH" type="text" id="txtMaKH" />
    </td>
</tr>
<tr>
    <td>Password</td>
    <td>:</td>
    <td>
        <input name="txtMatKhau" type="text" id="txtMatKhau" />
    </td>
</tr>
<tr>
    <td>Retype password</td>
    <td>:</td>
    <td>
        <input name="txtMatKhau2" type="text" id="txtMatKhau2" />
    </td>
</tr>
<tr>
    <td>Fullname</td>
    <td>:</td>
    <td>
        <input name="txtHoTen" type="text" id="txtHoTen"/>
    </td>
</tr>
<tr>
    <td>Gender</td>
    <td>:</td>
    <td>
        <input id="Male" type="radio" name="rdoGender" value="1" checked="checked" />Male
        <input id="Female" type="radio" name="rdoGender" value="0" />Female
    </td>
</tr>
<tr>
    <td>Email</td>
    <td>:</td>
    <td>
        <input name="txtEmail" type="text" id="txtEmail"/>
    </td>
</tr>
<tr>
    <td>Mobile</td>
    <td>:</td>
    <td>
        <input name="txtDienThoai" type="text" id="txtDienThoai"/>
    </td>
</tr>
<tr>
    <td>Date of birth</td>
    <td>:</td>
    <td>
        <input name="txtNgaySinh" type="text" id="txtNgaySinh" />
&nbsp;(Month/Day/Year)</td>
</tr>
<tr>
    <td>Address</td>
    <td>:</td>
    <td>
        <input name="txtDiaChi" type="text" id="txtDiaChi" />
    </td>
</tr>
<tr>
    <td>Photo</td>
    <td>:</td>
    <td>
        <input type="file" name="fupHinh" id="fupHinh" />
    </td>
</tr>
<tr>
    <td>Available</td>
    <td>:</td>
    <td>
      <input name="chkHieuLuc" type="checkbox" disabled="disabled" id="chkHieuLuc" checked />Activated from email!</td>
</tr>
<tr>
    <td>&nbsp;
        </td>
    <td>&nbsp;
        </td>
    <td>
        <input type="submit" name="btnSignUp" value="Sign Up" id="btnSignUp"/>
    </td>
</tr>
<tr>
  <td colspan="3"><?php echo $ThongBaoLoi ?>&nbsp;</td>
  </tr>
</table>
</form>